<%@page import="com.crossriver.crgis.database.service.Held_PlotsLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQuery"%>
<%@page import="com.crossriver.crgis.database.model.Held_Plots"%>
<%@page import="com.liferay.portal.service.LayoutLocalServiceUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>

<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>
 
<%@ page import="com.crossriver.crgis.database.model.Application_C_of_O" %>
<%@page import="com.crossriver.crgis.database.model.Individual_Information"%>
<%@page import="com.crossriver.crgis.database.model.History_Of_Information"%>
<%@page import="com.crossriver.crgis.database.model.Contact_Information"%>
<%@page import="com.crossriver.crgis.database.model.Property_Information"%>
<%@page import="com.crossriver.crgis.database.model.Supporting_Document"%>


<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ include file="/init.jsp"%>


<%

Application_C_of_O appl =
		(Application_C_of_O)request.getAttribute(
				ApplicationCofOConstants.APPL_C_OF_O_SESSION_ATTR);


Individual_Information indInfo = (Individual_Information)
			request.getAttribute(
				ApplicationCofOConstants.INDIVIDUAL_INFO_SESSION_ATTR);

List<History_Of_Information> history = (List<History_Of_Information>)
					request.getAttribute(
						ApplicationCofOConstants.HISTORY_INFO_SESSION_ATTR);


Contact_Information indContInfo = (Contact_Information)
		request.getAttribute(
			ApplicationCofOConstants.IND_CONTACT_SESSION_ATTR);

Property_Information propInfo = (Property_Information)
			request.getAttribute(
				ApplicationCofOConstants.PROPERTY_INFO_SESSION_ATTR);


List<Supporting_Document> suppDocs = (List<Supporting_Document>)
			request.getAttribute(
				ApplicationCofOConstants.SUPP_DOC_INFO_SESSION_ATTR);
List<Held_Plots> heldPlots = null;

//heldPlots = ApplicationActionUtil.getHeldPlots(actionRequest);
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Held_Plots.class)
 .add(PropertyFactoryUtil.forName("applicationId").eq(new String(propInfo.getApplicationId())));

try {
	 heldPlots=	Held_PlotsLocalServiceUtil.dynamicQuery(query);
} catch (SystemException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

%>


<div id="main">
	<h1>Application Status</h1>
	<div class="content">
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
			<td colspan="2" align="right">
			
			<%
		 		long plidMgtProfile = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), true, "/friendlyappcofo").getPlid();
		 	%>
		 	
		 	<liferay-portlet:actionURL portletName="printcofo_WAR_CRGISTransactionCofOportlet" plid="<%= plidMgtProfile %>" var="printerFriendly" >
		 		<liferay-portlet:param name="javax.portlet.action" value="printerFriendly"></liferay-portlet:param>
			  	<liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
	 		</liferay-portlet:actionURL>
	 		
	 		
			
			
			<form name="sampleform" method="POST" action="<%=printerFriendly %>" onsubmit="return createTarget(this.target)" target="formtarget">
				<input type="hidden" name="<portlet:namespace/>javax.portlet.action" value="printerFriendly"/>
				<input type="hidden" name="<portlet:namespace/>applicationId" value="<%= appl.getApplicationId() %>"/>
			</form>
						
						
			 <script type="text/javascript">
				// Popup window code
				function printerFriendlyPopup(url) {
					popupWindow = window.open(
						url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
				}
				</script>
				<a href="JavaScript:printerFriendlyPopup('<%= printerFriendly %>');">Printer Friendly Old</a>
			</td>
			</tr>
			<tr>
			<td colspan="2">
				<p>This is your Application Status page.</p>
				<%=appl.getStatus() %>
				<table width="100%" cellpadding="10px" cellspacing="0" style="font-size:12px" bgcolor="#FFFF62">
              		<tbody><tr>
              		<%
              		if(appl.getStatus().equalsIgnoreCase("SUBMITTED")){
              		%>
              		
	              	<td><img src="images/cnr-pending.png"></td>
	                  <td> Your application is currently <strong class="pending"><%=appl.getStatus() %>!</strong>.
	                  Please take note of your ID,<br><strong><%=appl.getReferenceNo() %></strong> while 
	                  your application is still being processed.
	                  </td>
	                 <%
              		}else if(appl.getStatus().equalsIgnoreCase("APPROVED")){
	                 %>
	                 <td><img src="images/success.png" width="30" height="30"></td>
	                 <td> Your application was successfull and has been <strong class="approved"><%=appl.getStatus() %>!</strong>.
                        Please take note of your Application ID, <strong><%=appl.getReferenceNo() %></strong>
                        </td>
	                 
	                 <%
              		}else if(appl.getStatus().equalsIgnoreCase("STOPPED")){
	                 %>
	                 <td><img src="images/failed.png"></td>
	                 <td> Your application has been <strong class="stopped"><%=appl.getStatus() %>!</strong>.
                        Please take note of your Application ID, <strong><%=appl.getReferenceNo() %></strong>. 
                        Contact us for further details.
                        </td>
	                 <%
              		}
	                 %>
	              </tr>
	              </tbody>
	           </table>
              <br>
              <p>Details of your application are detailed below.</p>
              <hr>
			</td>
			</tr>
		
			<tr>
			<td width="1%" valign="top">
				<aui:input name="applicationId" type="hidden" value="<%= appl.getApplicationId() %>"></aui:input>
				
			</td>
			<td width="99%" valign="top">
				<table width="100%" id="mainform">
					<tr>
						<td class="title" colspan="4">Application Summary</td>
					</tr>
					<tr>
						<td align="right" colspan="4">
						<hr>
						</td>
					</tr>

				<!-- Show this if this Re-CofO -->
				<%
				if (appl.getApplication().equalsIgnoreCase("RE-CERTIFICATION"))
				{
				%>
					<tr>
						<td colspan="4"><br>
							<liferay-portlet:actionURL var="editOldFileInfomation">
							  <liferay-portlet:param name="javax.portlet.action" value="editOldFileInfomation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Old File Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editOldFileInfomation %>"></a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Old Certificate of Occupancy Number</span> 
							<span class="data"><%= appl.getOldCofONo()%></span>
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<span class="dtitle">File Number</span> 
							<span class="data"><%= appl.getFileNo()%></span>
						</td>
					</tr>
				
				<%
				}
				%>
					
					<tr>
						<td colspan="4"><br>
							<liferay-portlet:actionURL var="editPersonalInformation">
							  <liferay-portlet:param name="javax.portlet.action" value="editPersonalInformation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Personal Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editPersonalInformation %>"></a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Full Name</span> 
							<span class="data"><%= indInfo.getLastName().toUpperCase() %>, <%= indInfo.getFirstName() %> <%= indInfo.getMiddleName() %></span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Sex</span> 
							<span class="data" > <%= indInfo.getGender() %></span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">Date Of Birth</span> 
							<span class="data"> <%= indInfo.getDateOfBirth() %> </span>
						</td>
						<td><br>
							<span class="dtitle">Occupation</span> 
							<span class="data" style="text-transform: uppercase"><%= indInfo.getOccupation() %></span>
						</td>
					</tr>
					
					<tr>
						<td width="25%"><br>
							<span class="dtitle">Marital Status</span> 
							<span class="data"><%= indInfo.getMaritalStatus() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle">Religion</span> 
							<span class="data"><%= indInfo.getReligion() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle">Education</span> 
							<span class="data"> <%= indInfo.getEducation() %></span>
						</td>
						<td width="25%"><br>
							<span class="dtitle"> No. Of Children</span> 
							<span class="data"><%= indInfo.getNoOfChildren() %></span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Nationality</span> 
							<span class="data"><%= indInfo.getNationality() %></span>
						</td>
						<td><br>
							<!--  <span>State Of Origin</span> <span class="data"
								style="text-transform: uppercase">
									<%= indInfo.getStateOfOrigin() %>
								</span>-->
						</td>
						<td><br>
							<span class="dtitle">LGA</span> 
							<span class="data"> <%= indInfo.getLga()%> </span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editAddressInformation">
						  <liferay-portlet:param name="javax.portlet.action" value="editAddressInformation"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
						</liferay-portlet:actionURL>
						
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Address Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editAddressInformation %>"></a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<span class="dtitle">Contact Address</span> 
							<span class="data"> <%= indContInfo.getHouseNo() %>, <%= indContInfo.getAddressLine1() %><br><%= indContInfo.getAddressLine2() %>, </span>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">City/Town</span> 
							<span class="data"><%= indContInfo.getCity()%></span>
						</td>
						<td><br>
							<span class="dtitle">State</span> 
							<span class="data"><%= indContInfo.getState() %></span>
						</td>
						<td><br>
							<span class="dtitle">Country</span> 
							<span class="data"><%= indContInfo.getCountry() %></span>
						</td>
						<td>&nbsp;</td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">P.M.B Address</span> 
							<span class="data"><%= indContInfo.getPoBox() %></span>
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editContactInformation">
						  <liferay-portlet:param name="javax.portlet.action" value="editContactInformation"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
						</liferay-portlet:actionURL>
						
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Contact Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editContactInformation %>"></a></span>
							<br><hr>
						</td>
					</tr>
					
					<tr>
						<td><br>
							<span class="dtitle">Mobile Phone</span> 
							<span class="data"><%= indContInfo.getPhoneMobile() %></span>
						</td>
						<td ><br>
							<span class="dtitle">Office Phone </span>
							<span class="data"><%= indContInfo.getPhoneOffice() %></span>
						</td>
						<td ><br>
							<span class="dtitle">Home Phone </span>
							<span class="data"><%= indContInfo.getPhoneHome() %></span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Email Address</span> 
							<span class="data"><%= indContInfo.getEmailAddress() %></span>
						</td>
					</tr>
					
						<liferay-portlet:actionURL var="editApplicationHistory">
						  <liferay-portlet:param name="javax.portlet.action" value="editApplicationHistory"></liferay-portlet:param>
						  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
						</liferay-portlet:actionURL>
					
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Application History</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editApplicationHistory %>"></a></span><br>
							<hr>
						</td>
					</tr>
					
					<tr>
						<td colspan="4">
							<table id="tb" cellpadding="5">
								<tr class="tbtitle">
									<td>Application Number of Previous Application</td>
								</tr>
								<%
								for (int i =0; i<history.size(); i++){
									History_Of_Information hist  = history.get(i);
								%>
								<tr>
									<td>
									<%= hist.getOldApplicationId()%>
									</td>
								</tr>
								
								<%
								}
								%>
							</table>
						</td>
					</tr>
					
							<liferay-portlet:actionURL var="editPropertyInformation">
							  <liferay-portlet:param name="javax.portlet.action" value="editPropertyInformation"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>">"></liferay-portlet:param>
							</liferay-portlet:actionURL>
					
					<tr>
						<td colspan="4"><br>
							<span style="float: left; margin: 0; padding: 0" class="stitle">Property Information</span> 
							<span style="float: right; margin: 0; padding: 0"><a href="<%= editPropertyInformation %>"></a></span><br>
							<hr>
						</td>
					</tr>
					<tr>
						<td colspan="4">
						<table id="tb" cellpadding="5">
							<tr class="tbtitle">
								<td>Land Use:</td>
								<td>Land Purpose:</td>
							</tr>
							<tr>
								<td><%= appl.getLandUseType() %></td>
								<td><%= appl.getLandUsePurpose()%></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td ><br>
							<span class="dtitle">Property Type</span> 
							<span class="data"> <%= propInfo.getPropertyType()%></span>
						</td>
						<td><br>
							<span class="dtitle">Land Area</span> 
							<span class="data"><%= propInfo.getArea()%> <%= propInfo.getUom()%> </span>
						</td>
						<td><br>
							<span class="dtitle">Block No.</span> 
							<span class="data"> <%= propInfo.getBlockNo()%> </span>
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					
					<tr>
						<td colspan="2"><br>
							<span class="dtitle">Land Location</span> 
							<span class="data"><%= propInfo.getLandLocation()%> </span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">City/Town/Village</span> 
							<span class="data"><%= propInfo.getCity()%>, <%= propInfo.getState()%>, <%= propInfo.getCountry()%></span></td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle"> Please provide additional useful information that may assist the agency in processing your application.<br> </span>
							<span class="data"><%= propInfo.getOtherUsefulInformation()%></span>  
						</td>
					</tr>
					
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">What is the date on the Original Certifiate of Occupancy (CofO)?</span>
							<span class="data"><%= propInfo.getOrigCofODate()%></span>
						</td>
					</tr>
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Was the original allocation made to you?</span>
							<span class="data"><%= propInfo.getAllocationMadToYou()%></span> 
						</td>
					</tr>
					<tr>
						<td colspan="4"><br>
							<span class="dtitle">Do you have an assignment?</span>
							<span class="data"><%= propInfo.getAssignedToYou()%></span>
						</td>
					</tr>
					<tr>
						<td colspan="2"><br>
							<span class="dtitle">Specify Required Land Use</span> 
							<span class="data"><%= appl.getLandUseType()%></span>
						</td>
						<td colspan="2"><br>
							<span class="dtitle">Specify Purpose</span> 
							<span class="data"> <%= appl.getLandUsePurpose()%></span>
						</td>
					</tr>
					
							<liferay-portlet:actionURL var="editSupportingDoc">
							  <liferay-portlet:param name="javax.portlet.action" value="editSupportingDoc"></liferay-portlet:param>
							  <liferay-portlet:param name="applicationId" value="<%= appl.getApplicationId() %>"></liferay-portlet:param>
							</liferay-portlet:actionURL>	
							
					<tr>
						<td colspan="4"><br>
							<span class="stitle">Uploads</span> 
							<span style="float: right; margin: 0; padding: 0"> <a href="<%= editSupportingDoc %>"></a></span><br>
							<hr>
						</td>
					</tr>
					<tr>
						<td colspan="4"><span>Documents Uploaded</span></td>
					</tr>
					
					<tr>
						<td colspan="4">
							<table id="tb" cellpadding="5">
								<tr class="tbtitle">
									<td>Document Name</td>
									<td>File Name</td>
									<td>Document Type</td>
								</tr>
					
								<%
								for (int i = 0; i<suppDocs.size(); i++){
									Supporting_Document suppDoc = suppDocs.get(i);
								%>
								<tr>
									<td >
										<%= suppDoc.getDocumentName() %>
									</td>
									<td >
									 <%= suppDoc.getFileName() %>
										
									</td>
									<td >
									<%= suppDoc.getDocumentType() %>
									</td>
									
								</tr>
					
								<%
								}
								%>
							</table>
						</td>
					</tr>
					<tr>
					</tr>
				</table>
				</td>
			</tr>
		</table>
	</div>
</div>